home *** CD-ROM | disk | FTP | other *** search
Wrap
pppprrrriiiinnnnttttffff((((1111)))) pppprrrriiiinnnnttttffff((((1111)))) NNNNAAAAMMMMEEEE _pppp_rrrr_iiii_nnnn_tttt_ffff - print formatted output SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS _pppp_rrrr_iiii_nnnn_tttt_ffff _f_o_r_m_a_t [_a_r_g . . .] DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN The _pppp_rrrr_iiii_nnnn_tttt_ffff command converts, formats, and prints its _a_r_gs under control of the _f_o_r_m_a_t. It fully supports conversion specifications for strings (_%%%%_ssss descriptor); however, the results are undefined for the other conversion specifications not specifically mentioned below. _f_o_r_m_a_t a character string that contains three types of objects: 1) plain characters, which are simply copied to the output stream; 2) conversion specifications, each of which results in fetching zero or more _a_r_gs; and 3) C-language escape sequences, which are translated into the corresponding characters. _a_r_g string(s) to be printed under the control of _f_o_r_m_a_t. The results are undefined if there are insufficient _a_r_gs for the format. Each conversion specification is introduced by the character _%%%%. After the _%%%%, the following appear in sequence: An optional field, consisting of a decimal digit string followed by a _$$$$, specifying the next _a_r_g to be converted. If this field is not provided, the _a_r_g following the last _a_r_g converted is used. An optional decimal digit string specifying a minimum _f_i_e_l_d _w_i_d_t_h. If the converted value has fewer characters than the field width, it is padded on the left (or right, if the left-adjustment flag `_----' has been given) to the field width. The padding is with blanks unless the field width digit string starts with a zero, in which case the padding is with zeros. An optional _p_r_e_c_i_s_i_o_n that gives the maximum number of characters to be printed from a string in _%%%%_ssss conversion. The precision takes the form of a period (_....) followed by a decimal digit string; a null digit string is treated as zero (nothing is printed). Padding specified by the precision overrides the padding specified by the field width. That is, if _p_r_e_c_i_s_i_o_n is specified, its value is used to control the number of characters printed. A field width or precision or both may be indicated by an asterisk (_****) instead of a digit string. In this case, an integer _a_r_g supplies the field width or precision. The _a_r_g that is actually converted is not fetched until the conversion letter is seen, so the _a_r_gs specifying field width or precision must appear _b_e_f_o_r_e the _a_r_g (if any) to be converted. A negative field width argument is taken as a _````_----_'''' (left-adjustment) flag followed by a positive field width. If the precision argument is negative, it is changed to zero PPPPaaaaggggeeee 1111 pppprrrriiiinnnnttttffff((((1111)))) pppprrrriiiinnnnttttffff((((1111)))) (nothing is printed). In no case does a non-existent or small field width cause truncation of a field; if the result of a conversion is wider than the field width, the field is simply expanded to contain the conversion result. The conversion characters and their meanings are: _%%%%_eeee_,,,, _%%%%_EEEE_,,,, _%%%%_ffff_,,,, _%%%%_gggg _aaaa_nnnn_dddd _%%%%_GGGG These conversion specifications are not supported. _%%%%_bbbb The argument will be taken to be a string that may contain backslash-escape sequences. _%%%%_ssss The _a_r_g is taken to be a string and characters from the string are printed until a null character (_\\\\_0000) is encountered or the number of characters indicated by the precision specification is reached. If the precision is missing, it is taken to be infinite, so all characters up to the first null character are printed. A null value for _a_r_g yields undefined results. _%%%%_%%%% Print a _%%%%; no argument is converted. EEEEXXXXTTTTEEEENNNNDDDDEEEEDDDD DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN _p_r_i_n_t_f does not precede or follow output from the _%%%%_dddd or _%%%%_uuuu conversion specifications with blank characters not specified by the format operand. _p_r_i_n_t_f does not precede output from the _%%%%_oooo conversion specification with zeros not specified by the format operand. The following backslash-escape sequences are supported: File Format Notation (_\\\\_\\\\_,,,, _\\\\_aaaa_,,,, _\\\\_bbbb_,,,, _\\\\_ffff_,,,, _\\\\_nnnn_,,,, _\\\\_rrrr_,,,, _\\\\_tttt_,,,, _\\\\_vvvv), which will be converted to the characters they represent. _\\\\_0000_dddd_dddd_dddd, where ddd is a zero-, one-, two- or three-digit octal number that will be converted to a byte with the numeric value specified by the octal number_\\\\_cccc, which will not be written and will cause printf to ignore any remaining characters in the string operand containing it, any remaining string operands and any additional characters in the format operand. The interpretation of a backslash followed by any other sequence of characters is unspecified. Bytes from the converted string will be written until the end of the string or the number of bytes indicated by the precision specification is reached. If the precision is omitted, it will be taken to be infinite, so all bytes up to the end of the converted string will be written. For each specification that consumes an argument, the next argument operand will be evaluated and converted to the appropriate type for the conversion as PPPPaaaaggggeeee 2222 pppprrrriiiinnnnttttffff((((1111)))) pppprrrriiiinnnnttttffff((((1111)))) specified below. The format operand will be reused as often as necessary to satisfy the argument operands. Any extra _%%%%_cccc or _%%%%_ssss conversion specifications will be evaluated as if a null string argument were supplied; other extra conversion specifications will be evaluated as if a zero argument were supplied. If the format operand contains no conversion specifications and argument operands are present, the results are unspecified. If a character sequence in the format operand begins with a _%%%% character, but does not form a valid conversion specification, the behaviour is unspecified.The argument operands will be treated as strings if the corresponding conversion character is _%%%%_bbbb, _%%%%_cccc or _%%%%_ssss; otherwise, it will be evaluated as a C constant, as described by the ISO C standard, with the following extensions: A leading plus or minus sign will be allowed. If the leading character is a single- or double-quote, the value will be the numeric value in the underlying codeset of the character following the single- or double-quote. If an argument operand cannot be completely converted into an internal value appropriate to the corresponding conversion specification, a diagnostic message will be written to standard error and the utility will not exit with a zero exit status, but will continue processing any remaining operands and will write the value accumulated at the time the error was detected to standard output. EEEEXXXXIIIITTTT SSSSTTTTAAAATTTTUUUUSSSS The following exit values are returned: 0 Successful completion. >0 An error occurred. If an argument cannot be parsed correctly for the corresponding conversion specification, the printf utility is required to report an error. Thus, overflow and extraneous characters at the end of an argument being used for a numeric conversion are to be reported as errors. It is not considered an error if an argument operand is not completely used for a _%%%%_cccc or _%%%%_ssss conversion or if a string operand's first or second character is used to get the numeric value of a character. The printf utility is required to notify the user when conversion errors are detected while producing numeric output; thus, the following results would be expected with 32-bit twos-complement integers when %d is specified as the format operand: PPPPaaaaggggeeee 3333 pppprrrriiiinnnnttttffff((((1111)))) pppprrrriiiinnnnttttffff((((1111)))) _D_i_a_g_n_o_s_t_i_c _O_u_t_p_u_t printf: "5a" not completely converted printf: "9999999999" arithmetic overflow printf: "-9999999999" arithmetic overflow printf: "ABC" expected numeric value Note that the value shown on standard output is what would be expected as the return value from the function strtol. A similar correspondence exists between %u and strtoul. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS The command _pppp_rrrr_iiii_nnnn_tttt_ffff _''''_%%%%_ssss _%%%%_ssss _%%%%_ssss_\\\\_nnnn_'''' _GGGG_oooo_oooo_dddd _MMMM_oooo_rrrr_nnnn_iiii_nnnn_gggg _WWWW_oooo_rrrr_llll_dddd results in the output: Good Morning World The following command produces the same output. _pppp_rrrr_iiii_nnnn_tttt_ffff _''''_%%%%_2222_$$$$_ssss _%%%%_ssss _%%%%_1111_$$$$_ssss_\\\\_nnnn_'''' _WWWW_oooo_rrrr_llll_dddd _GGGG_oooo_oooo_dddd _MMMM_oooo_rrrr_nnnn_iiii_nnnn_gggg Here is an example that prints the first 6 characters of _$$$$_PPPP_AAAA_TTTT_HHHH left- adjusted in a 10-character field: _pppp_rrrr_iiii_nnnn_tttt_ffff _''''_FFFF_iiii_rrrr_ssss_tttt _6666 _cccc_hhhh_aaaa_rrrr_ssss _oooo_ffff _%%%%_ssss _aaaa_rrrr_eeee _%%%%_----_1111_0000_...._6666_ssss_...._0000 _$$$$_PPPP_AAAA_TTTT_HHHH _$$$$_PPPP_AAAA_TTTT_HHHH If _$$$$_PPPP_AAAA_TTTT_HHHH has the value _////_uuuu_ssss_rrrr_////_bbbb_iiii_nnnn_::::_////_uuuu_ssss_rrrr_////_llll_oooo_cccc_aaaa_llll_////_bbbb_iiii_nnnn, then the above command would print the following output: _FFFF_iiii_rrrr_ssss_tttt _6666 _cccc_hhhh_aaaa_rrrr_ssss _oooo_ffff _////_uuuu_ssss_rrrr_////_bbbb_iiii_nnnn_::::_////_uuuu_ssss_rrrr_////_llll_oooo_cccc_aaaa_llll_////_bbbb_iiii_nnnn _aaaa_rrrr_eeee _////_uuuu_ssss_rrrr_////_bbbb _.... To alert the user and then print and read a series of prompts: _pppp_rrrr_iiii_nnnn_tttt_ffff _""""_\\\\_aaaa_PPPP_llll_eeee_aaaa_ssss_eeee _ffff_iiii_llll_llll _iiii_nnnn _tttt_hhhh_eeee _ffff_oooo_llll_llll_oooo_wwww_iiii_nnnn_gggg_:::: _\\\\_nnnn_NNNN_aaaa_mmmm_eeee_:::: _"""" _rrrr_eeee_aaaa_dddd _nnnn_aaaa_mmmm_eeee _pppp_rrrr_iiii_nnnn_tttt_ffff _""""_PPPP_hhhh_oooo_nnnn_eeee _nnnn_uuuu_mmmm_bbbb_eeee_rrrr_:::: _"""" _rrrr_eeee_aaaa_dddd _pppp_hhhh_oooo_nnnn_eeee To read out a list of right and wrong answers from a file, calculate the percentage correctly, and print them out. The numbers are right- justified and separated by a single tab character. The percentage is written to one decimal place of accuracy: _wwww_hhhh_iiii_llll_eeee _rrrr_eeee_aaaa_dddd _rrrr_iiii_gggg_hhhh_tttt _wwww_rrrr_oooo_nnnn_gggg _;;;; _dddd_oooo _pppp_eeee_rrrr_cccc_eeee_nnnn_tttt_====_$$$$_((((_eeee_cccc_hhhh_oooo _""""_ssss_cccc_aaaa_llll_eeee_====_1111_;;;;_((((_$$$$_rrrr_iiii_gggg_hhhh_tttt_****_1111_0000_0000_))))_////_((((_$$$$_rrrr_iiii_gggg_hhhh_tttt_++++_$$$$_wwww_rrrr_oooo_nnnn_gggg_))))_"""" _|||| _bbbb_cccc_)))) _pppp_rrrr_iiii_nnnn_tttt_ffff _""""_%%%%_2222_dddd _rrrr_iiii_gggg_hhhh_tttt_%%%%_2222_dddd _wwww_rrrr_oooo_nnnn_gggg_((((_%%%%_ssss_%%%%_%%%%_))))_0000 _\\\\ _$$$$_rrrr_iiii_gggg_hhhh_tttt _$$$$_wwww_rrrr_oooo_nnnn_gggg _$$$$_pppp_eeee_rrrr_cccc_eeee_nnnn_tttt _dddd_oooo_nnnn_eeee _<<<< _dddd_aaaa_tttt_aaaa_bbbb_aaaa_ssss_eeee______ffff_iiii_llll_eeee PPPPaaaaggggeeee 4444 pppprrrriiiinnnnttttffff((((1111)))) pppprrrriiiinnnnttttffff((((1111)))) The command: _pppp_rrrr_iiii_nnnn_tttt_ffff _""""_%%%%_5555_dddd_%%%%_4444_dddd_\\\\_nnnn_"""" _1111 _2222_1111 _3333_2222_1111 _4444_3333_2222_1111 _5555_4444_3333_2222_1111 produces: _1111 _2222_1111 _3333_2222_1111 _4444_3333_2222_1111 _5555_4444_3333_2222_1111 _0000 Note that the format operand is used three times to print all of the given strings and that a 0 was supplied by printf to satisfy the last %4d conversion specification. SSSSEEEEEEEE AAAALLLLSSSSOOOO _pppp_rrrr_iiii_nnnn_tttt_ffff(3S) PPPPaaaaggggeeee 5555